package org.lqq.client;

import org.lqq.config.ServerFinderAndRegisterConfig;
import org.lqq.loadbalance.LoadBalancer;
import org.lqq.remoteClient.RemoteClient;
import org.lqq.serverRegisterAndFinder.ServerFinderAndRegister;
import org.lqq.serverRegisterAndFinder.serverFinder.ServerFinder;
import org.lqq.serverRegisterAndFinder.serverRegister.ServerRegister;

/**
 * Created by 李清泉 on 2017/10/26.
 *
 * @remark
 */
public abstract class AbstractClient implements Client {

    public void runAPP(String configPath) {
        ServerFinderAndRegisterConfig serverFinderAndRegisterConfig = getServerFinderAndRegisterConfig();
        ServerFinderAndRegister serverFinderAndRegister = getServerFinderAndRegister(serverFinderAndRegisterConfig);
        ServerRegister serverRegister = serverFinderAndRegister.getServerRegister();
        serverRegister.registerToServer("testApp","192.168.8.111:8080");
        ServerFinder serverFinder = serverFinderAndRegister.getServerFinder();
        LoadBalancer loadBalancer = createLoadBalancer();
        RemoteClient remoteClient = createRemoteClient(serverFinder, loadBalancer);
        saveRemoteClient(remoteClient);
    }

    protected  void saveRemoteClient(RemoteClient remoteClient){
        RemoteClientStore.setRemoteClient(remoteClient);
    }

    protected abstract ServerFinderAndRegisterConfig getServerFinderAndRegisterConfig();


    protected abstract ServerFinderAndRegister getServerFinderAndRegister(ServerFinderAndRegisterConfig serverFinderAndRegisterConfig);


    protected abstract LoadBalancer createLoadBalancer();

    protected abstract RemoteClient createRemoteClient(ServerFinder serverFinder, LoadBalancer loadBalancer);


}
